package com.um.jdy.platform.free.controller;


import com.um.jdy.common.charge.entity.dto.FreeUserDTO;
import com.um.jdy.common.charge.entity.po.FreeUser;
import com.um.jdy.common.device.entity.dto.StationDTO;
import com.um.jdy.common.device.entity.po.Station;
import com.um.jdy.common.device.entity.vo.StationVO;
import com.um.jdy.platform.free.entity.vo.FreeUserListVO;
import com.um.jdy.platform.free.manager.FreeUserManager;
import com.um.jdy.platform.member.entity.dto.MemberPageDTO;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 免费充电用户管理
 *
 * @author cs
 * 日期 2023/5/25
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "免费充电")
@Validated
@RestController
@RequestMapping("/api/v1/cms/free")
@ApiPermission("free")
@TokenRequired
public class FreeUserController extends BaseController<FreeUserManager> {

    /**
     * 查询分页
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("查询分页")
    @PostMapping("/user_page")
    public Response<Page<FreeUserListVO>> getFeePage(@RequestBody MemberPageDTO params){
        PageParams pageParams =  params.toPageParams(new String[]{"mobile","nickname"},new String[]{"u.mobile","u.nickname"});
        return manager.getFeePage(pageParams);
    }

    @ApiPermission("add")
    @ApiOperation("新增")
    @PostMapping
    public Response<FreeUser> add(@Valid @RequestBody FreeUserDTO dto) {
        return manager.addEntity(dto);
    }

    @ApiPermission("update")
    @ApiOperation("更新")
    @PutMapping({"{id}"})
    public Response<FreeUser> update(@PathVariable String id, @Valid @RequestBody FreeUserDTO dto) {
        return manager.updateEntity(id, dto);
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }
}
